1680871718619_api_tokens.ts ➔ up   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 14
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 14
c 0
b 0
f 0
rs 9.85
cc 1
1
import BaseSchema from '@ioc:Adonis/Lucid/Schema'
2
3
export default class extends BaseSchema {
4
  protected tableName = 'api_tokens'
5
6
  public async up() {
7
    this.schema.createTable(this.tableName, (table) => {
8
      table.increments('id').primary()
9
      table.integer('user_id').unsigned().references('id').inTable('users').onDelete('CASCADE')
10
      table.string('name').notNullable()
11
      table.string('type').notNullable()
12
      table.string('token', 64).notNullable().unique()
13
14
      /**
15
       * Uses timestampz for PostgreSQL and DATETIME2 for MSSQL
16
       */
17
      table.timestamp('expires_at', { useTz: true }).nullable()
18
      table.timestamp('created_at', { useTz: true }).notNullable()
19
    })
20
  }
21
22
  public async down() {
23
    this.schema.dropTable(this.tableName)
24
  }
25
}
26